import { http } from "@/utils/http";
import type { PersistentVolume, PersistentVolumeList } from "./types";
import type { BaseResponse } from "@/api/response";
import {
  k8sPathMergeReqs,
  type MakePathReq,
  type MergePathReq
} from "./apiHelper";

export class K8sPersistentVolume {
  baseReq: MakePathReq = {
    src: "persistentvolumes",
    app: ""
  };

  getPVList = (query: MergePathReq): BaseResponse<PersistentVolumeList> => {
    const api = k8sPathMergeReqs(query, this.baseReq);
    return http.get(api, { params: query.query });
  };

  getPVDetail = (
    query: MergePathReq,
    data?: PersistentVolume
  ): BaseResponse<PersistentVolume> => {
    const api = k8sPathMergeReqs(query, this.baseReq, data);
    return http.get(api);
  };

  updatePV = (query: MergePathReq, data?: PersistentVolume): BaseResponse => {
    const api = k8sPathMergeReqs(query, this.baseReq, data);
    return http.put(api, { data });
  };

  deletePV = (query: MergePathReq, data?: PersistentVolume): BaseResponse => {
    const api = k8sPathMergeReqs(query, this.baseReq, data);
    return http.delete(api, { data });
  };

  patchPV = (query: MergePathReq, data?: PersistentVolume): BaseResponse => {
    const api = k8sPathMergeReqs(query, this.baseReq, data);
    return http.patch(api, { data });
  };

  createPV = (query: MergePathReq, data?: PersistentVolume): BaseResponse => {
    const api = k8sPathMergeReqs(query, this.baseReq, data);
    return http.post(api, { data });
  };
}
